home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / displayInterObjects.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.0 KB  |  405 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  July, 1997
  22. //  Author:         Barb Balents
  23. //
  24. //  Description:
  25. //      This script allows toggling the display of intermediate objects
  26. //        such as those created by deformers to store the pre-deformed shape.
  27. //
  28. //  Input Arguments:
  29. //        int $state: whether to turn display on or off
  30. //
  31. //  Return Value:
  32. //      None.
  33. //
  34. //
  35. //  Method: futurePlug(string $node, string $plug)
  36. //
  37. //  Description:
  38. //  Given a $node and a $plug ($plug is optional on all
  39. //  nodes except deformers), this method returns the name
  40. //  of the plug that inputs the shape data from this
  41. //  node.
  42. //
  43. //  If it does not recognize the node type of the given
  44. //  node, it returns "".
  45. //
  46. //  Currently supported node types:
  47. //   lattice, nurbsSurface, nurbsCurve, mesh, groupParts, deformers,
  48. //   stitchSrf, trim, polyModifier, deleteComponent, makeGroup,
  49. //     detachSurface
  50. //
  51. global proc int plugMultiIndex(string $plug)
  52. //
  53. //  Method:   int plugMultiIndex(string $plug)
  54. //
  55. //  Description:
  56. //    Given a plug that contains a multiIndex, return the index
  57. //
  58. //    If no multiIndex is found, returns -1.
  59. //      If plug is a multi multi, returns the first multiIndex only.
  60. //
  61. {
  62.     string $buffer[], $buffer2[];
  63.     tokenize($plug,"[",$buffer);
  64.     if (size($buffer) != 2) {
  65.         return(-1);
  66.     }
  67.     tokenize($buffer[1],"]",$buffer2);
  68.     return $buffer2[0];
  69. }
  70.  
  71.  
  72.  
  73.  
  74. global proc string futurePlug(string $node, string $plug)
  75. {
  76.     string $nt = nodeType($node);
  77.     string $futureAttr = "";
  78.  
  79.     string $testSel[]= `ls -type geometryFilter $node`;
  80.     string $testMM[]= `ls -type polyBase $node`;
  81.     string $testAPI[]= `ls -type THsurfaceShape $node`;    
  82.     
  83.     if      ($nt == "lattice")        { $futureAttr = ".wl[0]"; }
  84.     else if ($nt == "nurbsSurface")    { $futureAttr = ".ws[0]"; }
  85.     else if ($nt == "nurbsCurve")     { $futureAttr = ".ws[0]"; }
  86.     else if ($nt == "stitchSrf")     { $futureAttr = ".os"; }
  87.     else if ($nt == "closeSurface")    { $futureAttr = ".os"; }
  88.     else if ($nt == "reverseSurface")    { $futureAttr = ".os"; }        
  89.     else if ($nt == "smoothCurve")     { $futureAttr = ".oc"; }
  90.     else if ($nt == "rebuildCurve")    { $futureAttr = ".oc"; }
  91.     else if ($nt == "reverseCurve")    { $futureAttr = ".oc"; }            
  92.     else if ($nt == "trim")         { $futureAttr = ".os"; }
  93.     else if ($nt == "untrim")         { $futureAttr = ".os"; }    
  94.     else if ($nt == "transformGeometry")   { $historyAttr = ".og"; }
  95.     else if ($nt == "mesh")         { $futureAttr = ".w[0]";  }
  96.     else if ($nt == "detachSurface") { $futureAttr = ".os[0]";  }    
  97.     else if ($nt == "groupParts")   { $futureAttr = ".og"; }
  98.     else if ($nt == "makeGroup")    { $futureAttr = ".og"; }
  99.     else if ($nt == "deleteComponent") { $futureAttr = ".og"; }    
  100.     else if (size($testSel)) {
  101.         int $index = plugMultiIndex($plug);
  102.         if ($index == -1) {
  103.             return("");
  104.         }
  105.         $futureAttr = (".og["+$index+"]");
  106.     } else if (size($testMM)) {
  107.         // TdnpolyBase
  108.         //
  109.         $futureAttr = ".output";
  110.     } else if (size($testAPI)) {
  111.         // plugin mesh
  112.         //
  113.         $futureAttr = ".outputSurface";
  114.     } else {        
  115.         return("");
  116.     }
  117.  
  118.     return ($node+$futureAttr);
  119. }
  120.  
  121. global proc string historyPlug(string $node, string $plug)
  122. //
  123. //  Method: historyPlug(string $node, string $plug)
  124. //
  125. //  Description:
  126. //  Given a $node and a $plug ($plug is optional on all
  127. //  nodes except deformers), this method returns the name
  128. //  of the plug that inputs the shape data into this
  129. //  node.
  130. //
  131. //  If it does not recognize the node type of the given
  132. //  node, it returns "".
  133. //
  134. //  Currently supported node types:
  135. //   lattice, nurbsSurface, nurbsCurve, mesh, groupParts, deformers,
  136. //   stitchSrf, trim, polyModifier, deleteComponent, makeGroup,
  137. //     detachSurface
  138. //
  139. {
  140.     string $nt = nodeType($node);
  141.     string $historyAttr = "";
  142.  
  143.     string $testSel[]= `ls -type geometryFilter $node`;
  144.     string $testMM[]= `ls -type polyModifier $node`;
  145.     string $testAPI[]= `ls -type THsurfaceShape $node`;        
  146.  
  147.     if      ($nt == "lattice")        { $historyAttr = ".li"; }
  148.     else if ($nt == "nurbsSurface")    { $historyAttr = ".cr"; }
  149.     else if ($nt == "nurbsCurve")     { $historyAttr = ".cr"; }
  150.     else if ($nt == "stitchSrf")     { $historyAttr = ".is"; }
  151.     else if ($nt == "closeSurface")    { $historyAttr = ".is"; }
  152.     else if ($nt == "reverseSurface")    { $historyAttr = ".is"; }    
  153.     else if ($nt == "smoothCurve")     { $historyAttr = ".ic"; }
  154.     else if ($nt == "rebuildCurve") { $historyAttr = ".ic"; }
  155.     else if ($nt == "reverseCurve") { $historyAttr = ".ic"; }                
  156.     else if ($nt == "trim")             { $historyAttr = ".is"; }
  157.     else if ($nt == "untrim")        { $historyAttr = ".is"; }    
  158.     else if ($nt == "transformGeometry")   { $historyAttr = ".ig"; }
  159.     else if ($nt == "mesh")         { $historyAttr = ".i";  }
  160.     else if ($nt == "groupParts")   { $historyAttr = ".ig"; }
  161.     else if ($nt == "makeGroup")    { $historyAttr = ".ig"; }
  162.     else if ($nt == "deleteComponent") { $historyAttr = ".ig"; }        
  163.     else if ($nt == "insertKnotSurface") { $historyAttr = ".is"; }        
  164.     else if ($nt == "detachSurface")   { $historyAttr = ".is"; }    
  165.     else if (size($testSel)) {
  166.         int $index = plugMultiIndex($plug);
  167.         if ($index == -1) {
  168.             return("");
  169.         }
  170.         $historyAttr = (".input["+$index+"].inputGeometry");        
  171.     } else if (size($testMM)) {
  172.         $historyAttr = ".inputPolymesh";
  173.     } else if (size($testAPI)) {
  174.         // plugin mesh
  175.         //
  176.         $historyAttr = ".inputSurface";
  177.     } else {        
  178.         return("");
  179.     }
  180.  
  181.     return ($node+$historyAttr);
  182. }
  183.  
  184. proc string historyOrFuturePlug(string $node, string $plug, int $history)
  185. {
  186.     string $histPlug = "";
  187.     if ($history) $histPlug = historyPlug($node, $plug);
  188.     else          $histPlug = futurePlug($node, $plug);
  189.     return $histPlug;
  190. }
  191.  
  192. proc int connIsHistoryPlug(string $conns[])
  193. //
  194. // Return true if one of the strings in $conns is a history plug.
  195. //
  196. {
  197.     int $ii;
  198.     for ($ii = 0; $ii < size($conns); $ii++) {
  199.         string $buffer[];
  200.         tokenize($conns[$ii],".",$buffer);
  201.         string $node = $buffer[0];
  202.         string $hplug = historyPlug($node,$conns[$ii]);
  203.         string $shortName[] = `listAttr -sn $conns[$ii]`;
  204.         if ($hplug == ($node+"."+$shortName[0])) {
  205.             return 1;
  206.         }
  207.     }
  208.     return 0;
  209. }
  210.  
  211. proc string findOtherObject(string $shape, int $history)
  212. {
  213.     string $testInput[] = `ls -type controlPoint $shape`;
  214.     if (0 == size($testInput)) {
  215.         error("Invalid input to findOtherObject: "+$shape);
  216.         return 0;
  217.     }
  218.  
  219.     string $histPlug = historyOrFuturePlug($shape,"",$history);
  220.  
  221.     // make sure the object has history before starting the loop
  222.     //
  223.     string $conns[];
  224.     int $result = 0;
  225.  
  226.     while(true) {
  227.         $conns = `listConnections -p true $histPlug`;
  228.         if (! size($conns)) {
  229.             return "";
  230.         }
  231.         
  232.         // listConnections returns transform name for shapes, so make
  233.         // sure we get the node name and not the transform
  234.         //
  235.         string $buffer[];
  236.         tokenize($conns[0],".",$buffer);
  237.         $obj = $buffer[0];
  238.  
  239.         string $shapeCheck[] = `ls -type controlPoint $obj`;
  240.         if (size($shapeCheck)) {
  241.             return $obj;
  242.         }
  243.         
  244.         // get the name of the plug feeding the shape into this node
  245.         //
  246.         $histPlug = historyOrFuturePlug($obj,$conns[0],$history);
  247.         if ($histPlug == "") {
  248.             // stop, we can't find any more history
  249.             //
  250.             return "";
  251.         }
  252.     }
  253.     return "";
  254. }
  255.  
  256.  
  257. global proc displayInterObjects(int $state)
  258. //
  259. // Display ($state = 0) or Hide ($state = 1) intermediate objects.
  260. //
  261. {
  262.  
  263.     int $ii;
  264.     string $cmd;
  265.     string $selectCmd = "select -r ";     // for selection when toggling on
  266.     int $toggleCounter = 0;             // for error reporting
  267.     int $alreadyCounter = 0;            // for error reporting
  268.  
  269.     string $selObjs[5] = `ls -sl`;
  270.     if (0 == size($selObjs)) {
  271.         error("Must select deformed object.");
  272.         return;
  273.     }
  274.  
  275.     string $currSel[5] = `ls -sl -type controlPoint`;
  276.     if (size($currSel)) {
  277.         // find transform above selected shape
  278.         //
  279.         string $parents[] = `listRelatives -path -parent $currSel[0]`;
  280.         $selObjs = `listRelatives -path $parents[0]`;
  281.     } else {
  282.         // find shapes below the selected object
  283.         //
  284.         $selObjs = `listRelatives -path`;
  285.         if (1 == size($selObjs)) {
  286.             string $other = findOtherObject($selObjs[0],0);
  287.             if ("" == $other) {
  288.                 $other = findOtherObject($selObjs[0],1);
  289.             }
  290.             if ("" != $other) {
  291.                 $selObjs[1] = $other;
  292.             }
  293.         }
  294.     }
  295.     
  296.     // loop through the selected shapes
  297.     //
  298.     int $nsel = size($selObjs);
  299.     for ($ii = 0; $ii < $nsel; $ii++) {
  300.  
  301.         $cmd = "";
  302.         string $obj = $selObjs[$ii];
  303.         string $nt = nodeType($obj);
  304.         string $testAPI[]= `ls -type THsurfaceShape $obj`;    
  305.         string $futureAttr;
  306.         string $historyAttr;        
  307.  
  308.         if      ($nt == "lattice")        { $historyAttr = ".li"; }
  309.         else if ($nt == "nurbsSurface")    { $historyAttr = ".cr"; }
  310.         else if ($nt == "nurbsCurve")     { $historyAttr = ".cr"; }
  311.         else if ($nt == "mesh")         { $historyAttr = ".i";  }
  312.         else if ($nt == "subdiv")         { $historyAttr = ".cr";  }
  313.         else if (size($testAPI) > 0)    { $historyAttr = ".is"; }
  314.         else continue;        
  315.  
  316.         if      ($nt == "lattice")        { $futureAttr = ".wl[0]"; }
  317.         else if ($nt == "nurbsSurface")    { $futureAttr = ".ws[0]"; }
  318.         else if ($nt == "nurbsCurve")     { $futureAttr = ".ws[0]"; }
  319.         else if ($nt == "mesh")         { $futureAttr = ".w[0]";  }
  320.         else if ($nt == "subdiv")         { $futureAttr = ".ws[0]";  }
  321.         else if (size($testAPI) > 0)    { $futureAttr = ".ws[0]";  }        
  322.  
  323.         // $selFuture contains nodes in the future of the selected
  324.         //
  325.         int $hasFuture = 1;
  326.         string $selFuture[10] = `listConnections -p true ($obj+$futureAttr)`;
  327.         if (! $state && size($selFuture) == 0) {
  328.             continue;
  329.         }
  330.  
  331.         // $selHist contains nodes in the history of the selected
  332.         // shape. Continue if the node does not have history.
  333.         //
  334.         string $selHist[10] = `listConnections -p true ($obj+$historyAttr)`;
  335.         if (   $state
  336.                && (size($selFuture) == 0 || !connIsHistoryPlug($selFuture))
  337.                && size($selHist) > 0 ) {
  338.             $selectCmd += $obj + " ";
  339.             continue;
  340.         }
  341.  
  342.         // get the current state of the intermediate object attr
  343.         //
  344.         int $currentState = `getAttr ($obj+".io")`;
  345.  
  346.         if ($state) {
  347.             // toggle on the display of all except the final object in
  348.             // the history
  349.             //
  350.             if (! $currentState) {
  351.                 // construct the setAttr command
  352.                 //
  353.                 $cmd = "setAttr "+$obj+".io 1";
  354.             } else {
  355.                 $alreadyCounter++; // for error reporting
  356.             }
  357.         } else {
  358.             
  359.             if ($currentState) {
  360.                 // construct the setAttr command
  361.                 //
  362.                 $cmd = "setAttr "+$obj+".io 0";
  363.                 $selectCmd += $obj + " ";
  364.             } else {
  365.                 $alreadyCounter++; // for error reporting
  366.             }
  367.         }
  368.         if ($cmd != "") {
  369.             evalEcho $cmd;
  370.             $toggleCounter++;
  371.  
  372.             // If we're making subdivs visible, they need 
  373.             // to have a shader.
  374.             //
  375.             if( !$state && ( $nt == "subdiv" ) ) {
  376.                 subdAssignDefaultShader( $obj );
  377.             }
  378.         }
  379.     }
  380.  
  381.     // error reporting
  382.     //
  383.     if (0 == $toggleCounter) {
  384.         if ($alreadyCounter) {
  385.             if ($state) {
  386.                 error("Display is already toggled off.");
  387.             } else {
  388.                 error("Display is already toggled on.");
  389.             }
  390.         } else {
  391.             error("Found no intermediate objects.");
  392.         }
  393.     } else if ($state) {
  394.         // result reporting and select command to select deformed objects
  395.         //
  396.         evalEcho $selectCmd;        
  397.         print("// Result: Toggled off "+$toggleCounter+" objects. //\n");
  398.     } else {
  399.         // result reporting and select command to select inter objects
  400.         //
  401.         evalEcho $selectCmd;
  402.         print("// Result: Toggled on "+$toggleCounter+" objects. //\n");
  403.     }
  404. }
  405.